import 'package:equatable/equatable.dart';
import 'package:backend.core/core/domain/entities/api/app_store/api_app_store_transaction_revocation_info.dart';
import 'package:backend.purchases/infrastructure/dtos/api/api_time_dto.dart';
import 'package:backend.purchases/infrastructure/dtos/api/app_store/api_app_store_transaction_revocation_reason_dto.dart';

const kApiAppStoreTransactionRevocationInfoTimeKey = 'time';
const kApiAppStoreTransactionRevocationInfoReasonKey = 'reason';

class ApiAppStoreTransactionRevocationInfoDto extends Equatable {
  const ApiAppStoreTransactionRevocationInfoDto._internal({
    required this.timeDto,
    required this.reasonDto,
  });

  final ApiTimeDto timeDto;
  final ApiAppStoreTransactionRevocationReasonDto reasonDto;

  @override
  List<Object?> get props {
    return [
      timeDto,
      reasonDto,
    ];
  }

  factory ApiAppStoreTransactionRevocationInfoDto.fromEntity(
      ApiAppStoreTransactionRevocationInfo revocationInfo) {
    final timeDto = ApiTimeDto.fromEntity(revocationInfo.time);
    final reasonDto = ApiAppStoreTransactionRevocationReasonDto.fromEntity(revocationInfo.reason);

    return ApiAppStoreTransactionRevocationInfoDto._internal(
      timeDto: timeDto,
      reasonDto: reasonDto,
    );
  }

  Map<String, dynamic> toJson() {
    return {
      kApiAppStoreTransactionRevocationInfoTimeKey: timeDto.toString(),
      kApiAppStoreTransactionRevocationInfoReasonKey: reasonDto.toString(),
    };
  }
}
